using System;
using System.Collections.Generic;
using System.Linq;
using System.Configuration;
using Microsoft.VisualStudio.TestTools.UnitTesting;
//using T.FAS.Runtime.DataAccess.CDOEngine;
using T.FAS.Runtime.DataAccess.SPI;
using T.FAS.Runtime.DataAccess.Service;
using T.FAS.Runtime.Metadata.Entity.DataModel;
using T.FAS.Runtime.DataAccess.ShardingRule;

namespace T.FAS.Runtime.DataAccess.UnitTest
{
    [TestClass]
    public class DM_TestDeptUserModelBuilder
    {
        private string DeptUserCDOID = "a0bd40fc0649e61e82d7736e3a7e857d";  //CDO_DeptUser

        #region 方法
        [TestMethod]
        public void Init()
        {
            try
            {

                //var obj = ConfigurationManager.GetSection("redis") as RedisConfigSection;
                //return;
                //DataSourceService.GetInstance().SaveDataSource(CreateTMaster_SQLServerDataSource());
                //return;
                //清除旧数据
                //DataObjectManageService.GetInstance().DeleteDataObject(TestDAC_DeptDataObject.ID);
                //DataObjectManageService.GetInstance().DeleteDataObject(TestDAC_UserDataObject.ID);
                //CompositeDataObjectManageService.GetInstance().DeleteCompositeDataObject(DeptUserCDOID);

                ////保存新数据
                //DataObjectManageService.GetInstance().SaveDataObject(TestDAC_DeptDataObject);
                //DataObjectManageService.GetInstance().SaveDataObject(TestDAC_UserDataObject);
                //CompositeDataObjectManageService.GetInstance().SaveCompositeDataObject(DM_TestDeptUserCompositeDataObject);

                //调用获取DM方法
                //var queryModel = CompositeDataObjectRuntimeMetadataService.GetInstance().GetCompositeDataObject(DeptUserCDOID);
                //var json = Newtonsoft.Json.JsonConvert.SerializeObject(queryModel, new Newtonsoft.Json.JsonSerializerSettings
                //{
                //    ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                //});
                //Assert.IsTrue(queryModel != null);
            }
            catch (Exception e)
            {

                throw e;
            }
        }
        #endregion

        [TestMethod]
        public void TestCRUD()
        {
            try
            {
                //var data = DataAccessService.GetInstance().GetData(DeptUserCDOID, new QueryFilter());
                //Assert.IsTrue(data != null && data.First().Rows.Count > 0);
                //DataAccessService.GetInstance().Delete(DeptUserCDOID, new TestEntity().TestDAC_DeptTest().ID);
                //DataAccessService.GetInstance().Save(DeptUserCDOID, new TestEntity().TestDAC_DeptTest());
            }
            catch (Exception e)
            {

                throw;
            }
        }

        [TestMethod]
        public void TestUpdate()
        {
            try
            {
                var json = @"[
	{
		'CompositeNodeObject': '3686266ac7f0e71210e9eaa0cad2f4f4',
		'Data': [
			{
				'id': '001',
				'name': '济南一中123321',
				'remark': 'remark_1'
			},
			{
				'id': '002',
				'name': '济南二中123321',
				'remark': 'remark_2'
			}
		]
	},
	{
		'CompositeNodeObject': '1d0ef621fb44ffaf6c0cc967f3cd6f25',
		'Data': [
			{
				'id': '001',
				'name': '张三123321',
				'sex': '1',
                'remark': 'remark_1'
			},
			{
				'id': '002',
				'name': '李四123321',
				'sex': '1',
                'remark': 'remark_2'
			}
		]
	}
]";
                json = json.Replace("'", "\"");

                //var data = DataAccessService.GetInstance().GetData(DM_SchoolStuCompositeDataObject.ID, new QueryFilter());
                //DataAccessService.GetInstance().Delete(DM_SchoolStuCompositeDataObject.ID, new TestEntity().SchoolTest().ID);
                //DataAccessService.GetInstance().Update(DeptUserCDOID, json);
                //var queryCluster = DataAccessService.GetInstance().GetData(DM_SchoolStuCompositeDataObject.ID, new QueryFilter());
            }
            catch (Exception e)
            {

                throw;
            }
        }

        [TestMethod]
        public void TestSave()
        {
            try
            {
                var json = @"[
	{
		'CompositeNodeObject': '3686266ac7f0e71210e9eaa0cad2f4f4',
		'Data': [
			{
				'id': '001',
				'name': '济南一中',
				'remark': 'remark',
                'pid':'0'
			},
			{
				'id': '002',
				'name': '济南二中',
				'remark': 'remark',
                'pid':'0'
			}
		]
	},
	{
		'CompositeNodeObject': '1d0ef621fb44ffaf6c0cc967f3cd6f25',
		'Data': [
			{
				'id': '001',
				'name': '张三',
				'sex': '1',
                'deptid':'001',
                'remark': 'remark'
			},
			{
				'id': '002',
				'name': '李四',
				'sex': '1',
                'deptid':'002',
                'remark': 'remark'
			}
		]
	}
]";
                json = json.Replace("'", "\"");

                //var data = DataAccessService.GetInstance().GetData(DM_SchoolStuCompositeDataObject.ID, new QueryFilter());
                //DataAccessService.GetInstance().Delete(DM_SchoolStuCompositeDataObject.ID, new TestEntity().SchoolTest().ID);
                //DataAccessService.GetInstance().Save(DeptUserCDOID, json);
                //var queryCluster = DataAccessService.GetInstance().GetData(DM_SchoolStuCompositeDataObject.ID, new QueryFilter());
            }
            catch (Exception e)
            {

                throw;
            }
        }

        [TestMethod]
        public void TestDelete()
        {
            //DataAccessService.GetInstance().Delete(DeptUserCDOID, new List<string> { "001", "002" });
        }

        [TestMethod]
        public void TestSelfRelative()
        {
            try
            {
                //string DM_id = "DM_TestDeptUser";

                //var data = DataAccessService.GetInstance().GetData(DM_id, new QueryFilter());
            }
            catch (Exception e)
            {

                throw;
            }

        } 
    }
}
